<%@page import="java.text.DecimalFormat"%>
<%@page import="com.winexpress.order.OrderLine"%>
<%@page import="com.winexpress.order.OrderHistory"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="/WineXpressClient/resources/css/bootstrap.min.css" rel="stylesheet">
        <link href="/WineXpressClient/resources/css/bootstrap-theme.min.css" rel="stylesheet">
        <title>Customer Order</title>
    </head>
    <body>
        <div style="width: 210mm; margin: auto; border: solid;">
            <h2 align="center">Transaction History Report</h2>
            <% List<OrderHistory> history = (List<OrderHistory>) request.getAttribute("history"); %>
            <% if (history.isEmpty()) {%>
            <h4 align="center">No purchase history available.</h4>
            <%} else {%>
            <p align="center">User ID: <% out.print(history.get(0).getCustomer().getId());%> </p>
            <% for (OrderHistory oh : history) { %>
            <br/>
            <p class="bg-info" style="font-size: 18px;">Order Number: <% out.print(oh.getId()); %> </p>
            <p class="bg-info" style="font-size: 18px;">Date(DD-MM-YYYYY): <% out.print(oh.getDate().getDay()); %>-<% out.print(oh.getDate().getMonth()); %>-<% out.print(oh.getDate().getYear()); %></p>
            <table border="0" class="table table-striped">
                <tr>
                    <th style="width: 350px;">Wine</th>
                    <th style="text-align: center;">Qty</th>
                    <th style="text-align: right;">Price</th>
                    <th style="text-align: right;">Discount</th>
                    <th style="text-align: right;">Single Price</th>
                    <th style="text-align: right;">Final Price</th>
                </tr>
                <% List<OrderLine> ols = oh.getOrderLines(); %>
                <% double sum = 0.0; %>
                <% DecimalFormat df = new DecimalFormat("#.00");%>
                <% for (OrderLine ol : ols) {%>
                <tr>
                    <td><% out.print(ol.getWine().getName());%></td>
                    <td style="text-align: center;"><% out.print(ol.getQuantity());%></td>
                    <td style="text-align: right;"><% out.print(ol.getPrice()); %></td>
                    <td style="text-align: right;"><% out.print(ol.getDiscount());%></td>
                    <td style="text-align: right;"><% out.print(ol.getPrice() * (100 - ol.getDiscount()) / 100);%></td>
                    <% double a = ol.getQuantity() * ol.getPrice() * (100 - ol.getDiscount())/100; %>
                    <td style="text-align: right;"><% out.print(df.format(a));%></td>
                    <% sum += ol.getQuantity() * ol.getPrice() * (100 - ol.getDiscount()) / 100; %>
                </tr>
                <%}%>
                <tr>
                    <td colspan="5" align="right"><b>Order Sum:</td>
                    <td align="right"><% out.print(df.format(sum));%></td>
                </tr>
            </table>
            <%}%>
            <%}%>
        </div>
    </body>
</html>
